package com.sumainfor.zuul.controller.provider;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.zuul.service.impl.Feign.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 *
 * @Auther: zhlu
 * @Date: 2019/6/12 14:13
 * @Description:
 */
@RestController
@RequestMapping("/provider/message")
public class FeignMessage {

    @Autowired
    MessageService MessageService;

    /**
     * 功能描述:
     * 根据角色获取消息列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/10 20:21
     */
    @PostMapping("/MessageList")
    public JsonResult getMessageList(@RequestBody Map<String,Object> params){
        JsonResult result=new JsonResult();
        Pager pager=new Pager();
        if(FieldCheckUtil.isMapFieldNotNull(params,new String[]{"OpenPaging"})){
            //列表查询  0列表查询   1通知查询，二条
            if(params.get("OpenPaging").equals(1)||params.get("OpenPaging")=="1"){
                params.put("IfRead","0");//是否已读  0.未读  1.已读
                pager.setPageno(1);
                pager.setPagesize(2);
            }else{
                pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
                pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
            }
        }
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=MessageService.getMessageListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>> getMessageList=MessageService.getMessageList(params);
        result=pageUtils.getJsonResult(getMessageList, params, cout);
        return result;
    }

}
